package org.fixies.utils;

import java.io.Closeable;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;


/**
 * IOユーティリティ
 *
 * @author Kawasaki
 */
public final class IOUtils {


    public static void closeAll(Closeable... closeables) {
        for (Closeable c : closeables) {
            closeQuietly(c);
        }
    }

    public static void closeQuietly(Closeable c) {
        try {
            close(c);
        } catch (IOException ignorable) {
            Log.error("close failed.", ignorable);
        }
    }

    public static void close(Closeable c) throws IOException {
        if (c != null) {
            c.close();
        }
    }

    public static void rollbackQuietly(Connection c) {
        try {
            if (c != null) c.rollback();
        } catch (SQLException ignorable) {
            Log.error("close failed.", ignorable);
        }
    }

    public static void closeQuietly(Connection c) {
        try {
            close(c);
        } catch (SQLException ignorable) {
            ignorable = null;
        }
    }

    public static void close(Connection c) throws SQLException {
        if (c != null) {
            c.close();
        }
    }

    private IOUtils() {
    }
    
}
